#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<pthread.h>

void clean(void *arg)
{
	printf("%s\n",((char*)arg));
}

void *start(void *arg)
{
	printf("1\n");
	pthread_cleanup_push(clean,"第1次调用");
	pthread_cleanup_push(clean,"第2次调用");
	pthread_cleanup_push(clean,"第3次调用");
	printf("2\n");

	//while(1)
	//	sleep(1);
	sleep(2);
	pthread_exit(0);

	pthread_cleanup_pop(0);
	pthread_cleanup_pop(0);
	pthread_cleanup_pop(0);
}

int main()
{
	pthread_t tid;
	int ret;
	ret = pthread_create(&tid,NULL,start,NULL);
	if(ret)
	{
		printf("error!\n");
		exit(-1);
	}
	sleep(1);
	//pthread_cancel(tid);

	pthread_join(tid,NULL);
	exit(0);
}
